# Maintainer: Justin Kromlinger <hashworks@archlinux.org>
# Contributor: Marcus Hoffmann <bubu@bubu1.eu>

# This must be built against the version of dovecot being used,
# else mail delivery will fail.
# Specify the version of dovecot to be used here:
_dcpkgver=2.3.20
# Make sure to bump pkgrel if changing this.

pkgname=dovecot-fts-elastic
_reponame=fts-elastic
pkgver=1.1.0
pkgrel=4
pkgdesc="Dovecot FTS plugin for elasticsearch"
arch=(loong64 x86_64)
url="https://github.com/filiphanes/fts-elastic"
license=(MIT)
depends=("dovecot=${_dcpkgver}" json-c)
backup=('etc/dovecot/conf.d/90-fts.conf')
source=("$pkgname-$pkgver.tar.gz::$url/archive/$pkgver.tar.gz"
        "90-fts.conf")
sha256sums=('50aac69510cb504b6c7af7180a1d21fed3aadd47df30e5cd8ad50dfae5c36452'
            '3442fa7350055c7328bcdf2f666727b9a5d8c942a0bfe93044db344c80ad7e69')
install=dovecot-fts-elastic.install

build() {
  cd "${_reponame}-${pkgver}"

  ./autogen.sh
  ./configure \
    --prefix=/usr \
    --with-dovecot=/usr/lib/dovecot

  make
  make DESTDIR="$(pwd)/build" install
  sed -i -e 's/LLL/MMM/g' elastic7-schema.json
}

package() {
  install -Dm644 90-fts.conf "${pkgdir}/etc/dovecot/conf.d/90-fts.conf"

  cd "${_reponame}-${pkgver}"

  install -Dm644 build/usr/lib/dovecot/lib21_fts_elastic_plugin.so "${pkgdir}/usr/lib/dovecot/modules/lib21_fts_elastic_plugin.so"
  install -Dm644 elastic7-schema.json "${pkgdir}/usr/share/doc/${pkgname}/elastic7-schema.json"
  install -Dm644 README.md "${pkgdir}/usr/share/doc/${pkgname}/README.md"
  install -Dm644 COPYING.MIT "${pkgdir}/usr/share/licenses/${pkgname}/COPYING.MIT"
}

# vim: set tabstop=4:softtabstop=4:shiftwidth=4:noexpandtab
